home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / ds3100.md / gdb / infrun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-09  |  57.8 KB  |  1,958 lines

  1. /* Start (run) and stop the inferior process, for GDB.
  2.    Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Notes on the algorithm used in wait_for_inferior to determine if we
  21.    just did a subroutine call when stepping.  We have the following
  22.    information at that point:
  23.  
  24.                   Current and previous (just before this step) pc.
  25.           Current and previous sp.
  26.           Current and previous start of current function.
  27.  
  28.    If the starts of the functions don't match, then
  29.  
  30.        a) We did a subroutine call.
  31.  
  32.    In this case, the pc will be at the beginning of a function.
  33.  
  34.     b) We did a subroutine return.
  35.  
  36.    Otherwise.
  37.  
  38.     c) We did a longjmp.
  39.  
  40.    If we did a longjump, we were doing "nexti", since a next would
  41.    have attempted to skip over the assembly language routine in which
  42.    the longjmp is coded and would have simply been the equivalent of a
  43.    continue.  I consider this ok behaivior.  We'd like one of two
  44.    things to happen if we are doing a nexti through the longjmp()
  45.    routine: 1) It behaves as a stepi, or 2) It acts like a continue as
  46.    above.  Given that this is a special case, and that anybody who
  47.    thinks that the concept of sub calls is meaningful in the context
  48.    of a longjmp, I'll take either one.  Let's see what happens.  
  49.  
  50.    Acts like a subroutine return.  I can handle that with no problem
  51.    at all.
  52.  
  53.    -->So: If the current and previous beginnings of the current
  54.    function don't match, *and* the pc is at the start of a function,
  55.    we've done a subroutine call.  If the pc is not at the start of a
  56.    function, we *didn't* do a subroutine call.  
  57.  
  58.    -->If the beginnings of the current and previous function do match,
  59.    either: 
  60.  
  61.        a) We just did a recursive call.
  62.  
  63.        In this case, we would be at the very beginning of a
  64.        function and 1) it will have a prologue (don't jump to
  65.        before prologue, or 2) (we assume here that it doesn't have
  66.        a prologue) there will have been a change in the stack
  67.        pointer over the last instruction.  (Ie. it's got to put
  68.        the saved pc somewhere.  The stack is the usual place.  In
  69.        a recursive call a register is only an option if there's a
  70.        prologue to do something with it.  This is even true on
  71.        register window machines; the prologue sets up the new
  72.        window.  It might not be true on a register window machine
  73.        where the call instruction moved the register window
  74.        itself.  Hmmm.  One would hope that the stack pointer would
  75.        also change.  If it doesn't, somebody send me a note, and
  76.        I'll work out a more general theory.
  77.        bug-gdb@prep.ai.mit.edu).  This is true (albeit slipperly
  78.        so) on all machines I'm aware of:
  79.  
  80.           m68k:    Call changes stack pointer.  Regular jumps don't.
  81.  
  82.           sparc:    Recursive calls must have frames and therefor,
  83.                     prologues.
  84.  
  85.           vax:    All calls have frames and hence change the
  86.                     stack pointer.
  87.  
  88.     b) We did a return from a recursive call.  I don't see that we
  89.        have either the ability or the need to distinguish this
  90.        from an ordinary jump.  The stack frame will be printed
  91.        when and if the frame pointer changes; if we are in a
  92.        function without a frame pointer, it's the users own
  93.        lookout.
  94.  
  95.     c) We did a jump within a function.  We assume that this is
  96.        true if we didn't do a recursive call.
  97.  
  98.     d) We are in no-man's land ("I see no symbols here").  We
  99.        don't worry about this; it will make calls look like simple
  100.        jumps (and the stack frames will be printed when the frame
  101.        pointer moves), which is a reasonably non-violent response.
  102. */
  103.  
  104. #include "defs.h"
  105. #include <string.h>
  106. #include "symtab.h"
  107. #include "frame.h"
  108. #include "inferior.h"
  109. #include "breakpoint.h"
  110. #include "wait.h"
  111. #include "gdbcore.h"
  112. #include "signame.h"
  113. #include "command.h"
  114. #include "terminal.h"        /* For #ifdef TIOCGPGRP and new_tty */
  115. #include "target.h"
  116.  
  117. #include <signal.h>
  118.  
  119. /* unistd.h is needed to #define X_OK */
  120. #ifdef USG
  121. #include <unistd.h>
  122. #else
  123. #include <sys/file.h>
  124. #endif
  125.  
  126. #ifdef SET_STACK_LIMIT_HUGE
  127. #include <sys/time.h>
  128. #include <sys/resource.h>
  129.  
  130. extern int original_stack_limit;
  131. #endif /* SET_STACK_LIMIT_HUGE */
  132.  
  133. /* Prototypes for local functions */
  134.  
  135. static void
  136. signals_info PARAMS ((char *, int));
  137.  
  138. static void
  139. handle_command PARAMS ((char *, int));
  140.  
  141. static void
  142. sig_print_info PARAMS ((int));
  143.  
  144. static void
  145. sig_print_header PARAMS ((void));
  146.  
  147. static void
  148. remove_step_breakpoint PARAMS ((void));
  149.  
  150. static void
  151. insert_step_breakpoint PARAMS ((void));
  152.  
  153. static void
  154. resume PARAMS ((int, int));
  155.  
  156. static void
  157. resume_cleanups PARAMS ((int));
  158.  
  159. extern char **environ;
  160.  
  161. extern int sys_nerr;
  162. extern char *sys_errlist[];
  163.  
  164. extern struct target_ops child_ops;    /* In inftarg.c */
  165.  
  166. /* Sigtramp is a routine that the kernel calls (which then calls the
  167.    signal handler).  On most machines it is a library routine that
  168.    is linked into the executable.
  169.  
  170.    This macro, given a program counter value and the name of the
  171.    function in which that PC resides (which can be null if the
  172.    name is not known), returns nonzero if the PC and name show
  173.    that we are in sigtramp.
  174.  
  175.    On most machines just see if the name is sigtramp (and if we have
  176.    no name, assume we are not in sigtramp).  */
  177. #if !defined (IN_SIGTRAMP)
  178. #define IN_SIGTRAMP(pc, name) \
  179.   (name && !strcmp ("_sigtramp", name))
  180. #endif
  181.  
  182. /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
  183.    program.  It needs to examine the jmp_buf argument and extract the PC
  184.    from it.  The return value is non-zero on success, zero otherwise. */
  185. #ifndef GET_LONGJMP_TARGET
  186. #define GET_LONGJMP_TARGET(PC_ADDR) 0
  187. #endif
  188.  
  189.  
  190. /* Some machines have trampoline code that sits between function callers
  191.    and the actual functions themselves.  If this machine doesn't have
  192.    such things, disable their processing.  */
  193. #ifndef SKIP_TRAMPOLINE_CODE
  194. #define    SKIP_TRAMPOLINE_CODE(pc)    0
  195. #endif
  196.  
  197. /* For SVR4 shared libraries, each call goes through a small piece of
  198.    trampoline code in the ".init" section.  IN_SOLIB_TRAMPOLINE evaluates
  199.    to nonzero if we are current stopped in one of these. */
  200. #ifndef IN_SOLIB_TRAMPOLINE
  201. #define IN_SOLIB_TRAMPOLINE(pc,name)    0
  202. #endif
  203.  
  204. /* Notify other parts of gdb that might care that signal handling may
  205.    have changed for one or more signals. */
  206. #ifndef NOTICE_SIGNAL_HANDLING_CHANGE
  207. #define NOTICE_SIGNAL_HANDLING_CHANGE    /* No actions */
  208. #endif
  209.  
  210. #ifdef TDESC
  211. #include "tdesc.h"
  212. int safe_to_init_tdesc_context = 0;
  213. extern dc_dcontext_t current_context;
  214. #endif
  215.  
  216. /* Tables of how to react to signals; the user sets them.  */
  217.  
  218. static char signal_stop[NSIG];
  219. static char signal_print[NSIG];
  220. static char signal_program[NSIG];
  221.  
  222. /* Nonzero if breakpoints are now inserted in the inferior.  */
  223. /* Nonstatic for initialization during xxx_create_inferior. FIXME. */
  224.  
  225. /*static*/ int breakpoints_inserted;
  226.  
  227. /* Function inferior was in as of last step command.  */
  228.  
  229. static struct symbol *step_start_function;
  230.  
  231. /* Nonzero => address for special breakpoint for resuming stepping.  */
  232.  
  233. static CORE_ADDR step_resume_break_address;
  234.  
  235. /* Pointer to orig contents of the byte where the special breakpoint is.  */
  236.  
  237. static char step_resume_break_shadow[BREAKPOINT_MAX];
  238.  
  239. /* Nonzero means the special breakpoint is a duplicate
  240.    so it has not itself been inserted.  */
  241.  
  242. static int step_resume_break_duplicate;
  243.  
  244. /* Nonzero if we are expecting a trace trap and should proceed from it.  */
  245.  
  246. static int trap_expected;
  247.  
  248. /* Nonzero if the next time we try to continue the inferior, it will
  249.    step one instruction and generate a spurious trace trap.
  250.    This is used to compensate for a bug in HP-UX.  */
  251.  
  252. static int trap_expected_after_continue;
  253.  
  254. /* Nonzero means expecting a trace trap
  255.    and should stop the inferior and return silently when it happens.  */
  256.  
  257. int stop_after_trap;
  258.  
  259. /* Nonzero means expecting a trap and caller will handle it themselves.
  260.    It is used after attach, due to attaching to a process;
  261.    when running in the shell before the child program has been exec'd;
  262.    and when running some kinds of remote stuff (FIXME?).  */
  263.  
  264. int stop_soon_quietly;
  265.  
  266. /* Nonzero if pc has been changed by the debugger
  267.    since the inferior stopped.  */
  268.  
  269. int pc_changed;
  270.  
  271. /* Nonzero if proceed is being used for a "finish" command or a similar
  272.    situation when stop_registers should be saved.  */
  273.  
  274. int proceed_to_finish;
  275.  
  276. /* Save register contents here when about to pop a stack dummy frame,
  277.    if-and-only-if proceed_to_finish is set.
  278.    Thus this contains the return value from the called function (assuming
  279.    values are returned in a register).  */
  280.  
  281. char stop_registers[REGISTER_BYTES];
  282.  
  283. /* Nonzero if program stopped due to error trying to insert breakpoints.  */
  284.  
  285. static int breakpoints_failed;
  286.  
  287. /* Nonzero after stop if current stack frame should be printed.  */
  288.  
  289. static int stop_print_frame;
  290.  
  291. #ifdef NO_SINGLE_STEP
  292. extern int one_stepped;        /* From machine dependent code */
  293. extern void single_step ();    /* Same. */
  294. #endif /* NO_SINGLE_STEP */
  295.  
  296.  
  297. /* Things to clean up if we QUIT out of resume ().  */
  298. /* ARGSUSED */
  299. static void
  300. resume_cleanups (arg)
  301.      int arg;
  302. {
  303.   normal_stop ();
  304. }
  305.  
  306. /* Resume the inferior, but allow a QUIT.  This is useful if the user
  307.    wants to interrupt some lengthy single-stepping operation
  308.    (for child processes, the SIGINT goes to the inferior, and so
  309.    we get a SIGINT random_signal, but for remote debugging and perhaps
  310.    other targets, that's not true).
  311.  
  312.    STEP nonzero if we should step (zero to continue instead).
  313.    SIG is the signal to give the inferior (zero for none).  */
  314. static void
  315. resume (step, sig)
  316.      int step;
  317.      int sig;
  318. {
  319.   struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
  320.   QUIT;
  321.  
  322. #ifdef NO_SINGLE_STEP
  323.   if (step) {
  324.     single_step(sig);    /* Do it the hard way, w/temp breakpoints */
  325.     step = 0;        /* ...and don't ask hardware to do it.  */
  326.   }
  327. #endif
  328.  
  329.   /* Handle any optimized stores to the inferior NOW...  */
  330. #ifdef DO_DEFERRED_STORES
  331.   DO_DEFERRED_STORES;
  332. #endif
  333.  
  334.   target_resume (step, sig);
  335.   discard_cleanups (old_cleanups);
  336. }
  337.  
  338.  
  339. /* Clear out all variables saying what to do when inferior is continued.
  340.    First do this, then set the ones you want, then call `proceed'.  */
  341.  
  342. void
  343. clear_proceed_status ()
  344. {
  345.   trap_expected = 0;
  346.   step_range_start = 0;
  347.   step_range_end = 0;
  348.   step_frame_address = 0;
  349.   step_over_calls = -1;
  350.   step_resume_break_address = 0;
  351.   stop_after_trap = 0;
  352.   stop_soon_quietly = 0;
  353.   proceed_to_finish = 0;
  354.   breakpoint_proceeded = 1;    /* We're about to proceed... */
  355.  
  356.   /* Discard any remaining commands or status from previous stop.  */
  357.   bpstat_clear (&stop_bpstat);
  358. }
  359.  
  360. /* Basic routine for continuing the program in various fashions.
  361.  
  362.    ADDR is the address to resume at, or -1 for resume where stopped.
  363.    SIGGNAL is the signal to give it, or 0 for none,
  364.      or -1 for act according to how it stopped.
  365.    STEP is nonzero if should trap after one instruction.
  366.      -1 means return after that and print nothing.
  367.      You should probably set various step_... variables
  368.      before calling here, if you are stepping.
  369.  
  370.    You should call clear_proceed_status before calling proceed.  */
  371.  
  372. void
  373. proceed (addr, siggnal, step)
  374.      CORE_ADDR addr;
  375.      int siggnal;
  376.      int step;
  377. {
  378.   int oneproc = 0;
  379.  
  380.   if (step > 0)
  381.     step_start_function = find_pc_function (read_pc ());
  382.   if (step < 0)
  383.     stop_after_trap = 1;
  384.  
  385.   if (addr == (CORE_ADDR)-1)
  386.     {
  387.       /* If there is a breakpoint at the address we will resume at,
  388.      step one instruction before inserting breakpoints
  389.      so that we do not stop right away.  */
  390.  
  391.       if (!pc_changed && breakpoint_here_p (read_pc ()))
  392.     oneproc = 1;
  393.     }
  394.   else
  395.     {
  396.       write_register (PC_REGNUM, addr);
  397. #ifdef NPC_REGNUM
  398.       write_register (NPC_REGNUM, addr + 4);
  399. #ifdef NNPC_REGNUM
  400.       write_register (NNPC_REGNUM, addr + 8);
  401. #endif
  402. #endif
  403.     }
  404.  
  405.   if (trap_expected_after_continue)
  406.     {
  407.       /* If (step == 0), a trap will be automatically generated after
  408.      the first instruction is executed.  Force step one
  409.      instruction to clear this condition.  This should not occur
  410.      if step is nonzero, but it is harmless in that case.  */
  411.       oneproc = 1;
  412.       trap_expected_after_continue = 0;
  413.     }
  414.  
  415.   if (oneproc)
  416.     /* We will get a trace trap after one instruction.
  417.        Continue it automatically and insert breakpoints then.  */
  418.     trap_expected = 1;
  419.   else
  420.     {
  421.       int temp = insert_breakpoints ();
  422.       if (temp)
  423.     {
  424.       print_sys_errmsg ("ptrace", temp);
  425.       error ("Cannot insert breakpoints.\n\
  426. The same program may be running in another process.");
  427.     }
  428.       breakpoints_inserted = 1;
  429.     }
  430.  
  431.   /* Install inferior's terminal modes.  */
  432.   target_terminal_inferior ();
  433.  
  434.   if (siggnal >= 0)
  435.     stop_signal = siggnal;
  436.   /* If this signal should not be seen by program,
  437.      give it zero.  Used for debugging signals.  */
  438.   else if (stop_signal < NSIG && !signal_program[stop_signal])
  439.     stop_signal= 0;
  440.  
  441.   /* Resume inferior.  */
  442.   resume (oneproc || step || bpstat_should_step (), stop_signal);
  443.  
  444.   /* Wait for it to stop (if not standalone)
  445.      and in any case decode why it stopped, and act accordingly.  */
  446.  
  447.   wait_for_inferior ();
  448.   normal_stop ();
  449. }
  450.  
  451. /* Record the pc and sp of the program the last time it stopped.
  452.    These are just used internally by wait_for_inferior, but need
  453.    to be preserved over calls to it and cleared when the inferior
  454.    is started.  */
  455. static CORE_ADDR prev_pc;
  456. static CORE_ADDR prev_sp;
  457. static CORE_ADDR prev_func_start;
  458. static char *prev_func_name;
  459.  
  460.  
  461. /* Start an inferior Unix child process and sets inferior_pid to its pid.
  462.    EXEC_FILE is the file to run.
  463.    ALLARGS is a string containing the arguments to the program.
  464.    ENV is the environment vector to pass.  Errors reported with error().  */
  465.  
  466. #ifndef SHELL_FILE
  467. #define SHELL_FILE "/bin/sh"
  468. #endif
  469.  
  470. void
  471. child_create_inferior (exec_file, allargs, env)
  472.      char *exec_file;
  473.      char *allargs;
  474.      char **env;
  475. {
  476.   int pid;
  477.   char *shell_command;
  478.   char *shell_file;
  479.   static char default_shell_file[] = SHELL_FILE;
  480.   int len;
  481.   int pending_execs;
  482.   /* Set debug_fork then attach to the child while it sleeps, to debug. */
  483.   static int debug_fork = 0;
  484.   /* This is set to the result of setpgrp, which if vforked, will be visible
  485.      to you in the parent process.  It's only used by humans for debugging.  */
  486.   static int debug_setpgrp = 657473;
  487.   char **save_our_env;
  488.  
  489.   /* The user might want tilde-expansion, and in general probably wants
  490.      the program to behave the same way as if run from
  491.      his/her favorite shell.  So we let the shell run it for us.
  492.      FIXME, this should probably search the local environment (as
  493.      modified by the setenv command), not the env gdb inherited.  */
  494. #ifdef sprite
  495.   shell_file = "/sprite/cmds/sh";
  496. #else /* sprite */
  497.   shell_file = getenv ("SHELL");
  498. #endif /* sprite */
  499.   if (shell_file == NULL)
  500.     shell_file = default_shell_file;
  501.   
  502.   len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10;
  503.   /* If desired, concat something onto the front of ALLARGS.
  504.      SHELL_COMMAND is the result.  */
  505. #ifdef SHELL_COMMAND_CONCAT
  506.   shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + len);
  507.   strcpy (shell_command, SHELL_COMMAND_CONCAT);
  508. #else
  509.   shell_command = (char *) alloca (len);
  510.   shell_command[0] = '\0';
  511. #endif
  512.   strcat (shell_command, "exec ");
  513. #ifdef sprite
  514.   strcat (shell_command, "debug ");
  515. #endif
  516.   strcat (shell_command, exec_file);
  517.   strcat (shell_command, " ");
  518.   strcat (shell_command, allargs);
  519.  
  520.   /* exec is said to fail if the executable is open.  */
  521.   close_exec_file ();
  522.  
  523.   /* Retain a copy of our environment variables, since the child will
  524.      replace the value of  environ  and if we're vforked, we have to 
  525.      restore it.  */
  526.   save_our_env = environ;
  527.  
  528.   /* Tell the terminal handling subsystem what tty we plan to run on;
  529.      it will just record the information for later.  */
  530.  
  531.   new_tty_prefork (inferior_io_terminal);
  532.  
  533.   /* It is generally good practice to flush any possible pending stdio
  534.      output prior to doing a fork, to avoid the possibility of both the
  535.      parent and child flushing the same data after the fork. */
  536.  
  537.   fflush (stdout);
  538.   fflush (stderr);
  539.  
  540. #ifdef sprite
  541.   pid = fork();
  542. #else
  543. #if defined(USG) && !defined(HAVE_VFORK)
  544.   pid = fork ();
  545. #else
  546.   if (debug_fork)
  547.     pid = fork ();
  548.   else
  549.     pid = vfork ();
  550. #endif
  551. #endif
  552.  
  553.   if (pid < 0)
  554.     perror_with_name ("vfork");
  555.  
  556.   if (pid == 0)
  557.     {
  558.       if (debug_fork) 
  559.     sleep (debug_fork);
  560.  
  561. #ifdef TIOCGPGRP
  562.       /* Run inferior in a separate process group.  */
  563. #ifdef NEED_POSIX_SETPGID
  564.       debug_setpgrp = setpgid (0, 0);
  565. #else
  566. #if defined(USG) && !defined(SETPGRP_ARGS)
  567.       debug_setpgrp = setpgrp ();
  568. #else
  569.       debug_setpgrp = setpgrp (getpid (), getpid ());
  570. #endif /* USG */
  571. #endif /* NEED_POSIX_SETPGID */
  572.       if (debug_setpgrp == -1)
  573.      perror("setpgrp failed in child");
  574. #endif /* TIOCGPGRP */
  575.  
  576. #ifdef SET_STACK_LIMIT_HUGE
  577.       /* Reset the stack limit back to what it was.  */
  578.       {
  579.     struct rlimit rlim;
  580.  
  581.     getrlimit (RLIMIT_STACK, &rlim);
  582.     rlim.rlim_cur = original_stack_limit;
  583.     setrlimit (RLIMIT_STACK, &rlim);
  584.       }
  585. #endif /* SET_STACK_LIMIT_HUGE */
  586.  
  587.       /* Ask the tty subsystem to switch to the one we specified earlier
  588.      (or to share the current terminal, if none was specified).  */
  589.  
  590.       new_tty ();
  591.  
  592.       /* Changing the signal handlers for the inferior after
  593.      a vfork can also change them for the superior, so we don't mess
  594.      with signals here.  See comments in
  595.      initialize_signals for how we get the right signal handlers
  596.      for the inferior.  */
  597.  
  598. #ifdef sprite
  599.       /*
  600.        * This appears to be needed on Sprite.
  601.        */
  602.       signal (SIGQUIT, SIG_DFL);
  603.       signal (SIGINT, SIG_DFL);
  604. #endif
  605.  
  606. #ifdef USE_PROC_FS
  607.       proc_set_exec_trap ();        /* Use SVR4 /proc interface */
  608. #else
  609.       call_ptrace (0, 0, 0, 0);        /* "Trace me, Dr. Memory!" */
  610. #endif
  611.  
  612.       /* There is no execlpe call, so we have to set the environment
  613.      for our child in the global variable.  If we've vforked, this
  614.      clobbers the parent, but environ is restored a few lines down
  615.      in the parent.  By the way, yes we do need to look down the
  616.      path to find $SHELL.  Rich Pixley says so, and I agree.  */
  617.       environ = env;
  618.       execlp (shell_file, shell_file, "-c", shell_command, (char *)0);
  619.       fprintf (stderr, "Cannot exec %s: %s.\n", shell_file,
  620.            errno < sys_nerr ? sys_errlist[errno] : "unknown error");
  621.       fflush (stderr);
  622.       _exit (0177);
  623.     }
  624.  
  625.   /* Restore our environment in case a vforked child clob'd it.  */
  626.   environ = save_our_env;
  627.  
  628.   /* Now that we have a child process, make it our target.  */
  629.   push_target (&child_ops);
  630.  
  631. #ifdef CREATE_INFERIOR_HOOK
  632.   CREATE_INFERIOR_HOOK (pid);
  633. #endif  
  634.  
  635. /* The process was started by the fork that created it,
  636.    but it will have stopped one instruction after execing the shell.
  637.    Here we must get it up to actual execution of the real program.  */
  638.  
  639.   inferior_pid = pid;        /* Needed for wait_for_inferior stuff below */
  640.  
  641.   clear_proceed_status ();
  642.  
  643.   /* We will get a trace trap after one instruction.
  644.      Continue it automatically.  Eventually (after shell does an exec)
  645.      it will get another trace trap.  Then insert breakpoints and continue.  */
  646.  
  647. #ifdef START_INFERIOR_TRAPS_EXPECTED
  648.   pending_execs = START_INFERIOR_TRAPS_EXPECTED;
  649. #else
  650.   pending_execs = 2;
  651. #endif
  652.  
  653.   init_wait_for_inferior ();
  654.  
  655.   /* Set up the "saved terminal modes" of the inferior
  656.      based on what modes we are starting it with.  */
  657.   target_terminal_init ();
  658.  
  659.   /* Install inferior's terminal modes.  */
  660.   target_terminal_inferior ();
  661.  
  662.   while (1)
  663.     {
  664.       stop_soon_quietly = 1;    /* Make wait_for_inferior be quiet */
  665.       wait_for_inferior ();
  666.       if (stop_signal != SIGTRAP)
  667.     {
  668.       /* Let shell child handle its own signals in its own way */
  669.       /* FIXME, what if child has exit()ed?  Must exit loop somehow */
  670.       resume (0, stop_signal);
  671.     }
  672.       else
  673.     {
  674.       /* We handle SIGTRAP, however; it means child did an exec.  */
  675.       if (0 == --pending_execs)
  676.         break;
  677.       resume (0, 0);        /* Just make it go on */
  678.     }
  679.     }
  680.   stop_soon_quietly = 0;
  681.  
  682.   /* We are now in the child process of interest, having exec'd the
  683.      correct program, and are poised at the first instruction of the
  684.      new program.  */
  685. #ifdef SOLIB_CREATE_INFERIOR_HOOK
  686.   SOLIB_CREATE_INFERIOR_HOOK (pid);
  687. #endif
  688.  
  689.   /* Should this perhaps just be a "proceed" call?  FIXME */
  690.   insert_step_breakpoint ();
  691.   breakpoints_failed = insert_breakpoints ();
  692.   if (!breakpoints_failed)
  693.     {
  694.       breakpoints_inserted = 1;
  695.       target_terminal_inferior();
  696.       /* Start the child program going on its first instruction, single-
  697.      stepping if we need to.  */
  698.       resume (bpstat_should_step (), 0);
  699.       wait_for_inferior ();
  700.       normal_stop ();
  701.     }
  702. }
  703.  
  704. /* Start remote-debugging of a machine over a serial link.  */
  705.  
  706. void
  707. start_remote ()
  708. {
  709.   init_wait_for_inferior ();
  710.   clear_proceed_status ();
  711.   stop_soon_quietly = 1;
  712.   trap_expected = 0;
  713.   wait_for_inferior ();
  714.   normal_stop ();
  715. }
  716.  
  717. /* Initialize static vars when a new inferior begins.  */
  718.  
  719. void
  720. init_wait_for_inferior ()
  721. {
  722.   /* These are meaningless until the first time through wait_for_inferior.  */
  723.   prev_pc = 0;
  724.   prev_sp = 0;
  725.   prev_func_start = 0;
  726.   prev_func_name = NULL;
  727.  
  728.   trap_expected_after_continue = 0;
  729.   breakpoints_inserted = 0;
  730.   mark_breakpoints_out ();
  731.   stop_signal = 0;        /* Don't confuse first call to proceed(). */
  732. }
  733.  
  734.  
  735. /* Attach to process PID, then initialize for debugging it
  736.    and wait for the trace-trap that results from attaching.  */
  737.  
  738. void
  739. child_attach (args, from_tty)
  740.      char *args;
  741.      int from_tty;
  742. {
  743.   char *exec_file;
  744.   int pid;
  745.  
  746.   dont_repeat();
  747.  
  748.   if (!args)
  749.     error_no_arg ("process-id to attach");
  750.  
  751. #ifndef ATTACH_DETACH
  752.   error ("Can't attach to a process on this machine.");
  753. #else
  754. #ifdef sprite
  755.   /*
  756.    * Since Sprite pids are displayed in hex the atoi doesn't work. We
  757.    * allow the attach command to use any C expression.
  758.    */
  759.   pid = value_as_long (evaluate_expression (parse_expression (args)));
  760. #else
  761.   pid = atoi (args);
  762. #endif /* Sprite */
  763.   if (target_has_execution)
  764.     {
  765.       if (query ("A program is being debugged already.  Kill it? "))
  766.     target_kill ();
  767.       else
  768.     error ("Inferior not killed.");
  769.     }
  770.  
  771.   exec_file = (char *) get_exec_file (1);
  772.  
  773.   if (from_tty)
  774.     {
  775.       printf ("Attaching program: %s pid %d\n",
  776.           exec_file, pid);
  777.       fflush (stdout);
  778.     }
  779.  
  780.   attach (pid);
  781.   inferior_pid = pid;
  782.   push_target (&child_ops);
  783.  
  784.   mark_breakpoints_out ();
  785.   target_terminal_init ();
  786.   clear_proceed_status ();
  787.   stop_soon_quietly = 1;
  788.   /*proceed (-1, 0, -2);*/
  789.   target_terminal_inferior ();
  790.   wait_for_inferior ();
  791. #ifdef SOLIB_ADD
  792.   SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0);
  793. #endif
  794.   normal_stop ();
  795. #endif  /* ATTACH_DETACH */
  796. }
  797.  
  798. /* Wait for control to return from inferior to debugger.
  799.    If inferior gets a signal, we may decide to start it up again
  800.    instead of returning.  That is why there is a loop in this function.
  801.    When this function actually returns it means the inferior
  802.    should be left stopped and GDB should read more commands.  */
  803.  
  804. void
  805. wait_for_inferior ()
  806. {
  807.   WAITTYPE w;
  808.   int another_trap;
  809.   int random_signal;
  810.   CORE_ADDR stop_sp;
  811.   CORE_ADDR stop_func_start;
  812.   char *stop_func_name;
  813.   CORE_ADDR prologue_pc, tmp;
  814.   int stop_step_resume_break;
  815.   struct symtab_and_line sal;
  816.   int remove_breakpoints_on_following_step = 0;
  817.   int current_line;
  818.   int handling_longjmp = 0;    /* FIXME */
  819.  
  820.   sal = find_pc_line(prev_pc, 0);
  821.   current_line = sal.line;
  822.  
  823.   while (1)
  824.     {
  825.       /* Clean up saved state that will become invalid.  */
  826.       pc_changed = 0;
  827.       flush_cached_frames ();
  828.       registers_changed ();
  829.  
  830.       target_wait (&w);
  831.  
  832. #ifdef SIGTRAP_STOP_AFTER_LOAD
  833.  
  834.       /* Somebody called load(2), and it gave us a "trap signal after load".
  835.          Ignore it gracefully. */
  836.  
  837.       SIGTRAP_STOP_AFTER_LOAD (w);
  838. #endif
  839.  
  840.       /* See if the process still exists; clean up if it doesn't.  */
  841.       if (WIFEXITED (w))
  842.     {
  843.       target_terminal_ours ();    /* Must do this before mourn anyway */
  844.       if (WEXITSTATUS (w))
  845.         printf ("\nProgram exited with code 0%o.\n", 
  846.              (unsigned int)WEXITSTATUS (w));
  847.       else
  848.         if (!batch_mode())
  849.           printf ("\nProgram exited normally.\n");
  850.       fflush (stdout);
  851.       target_mourn_inferior ();
  852. #ifdef NO_SINGLE_STEP
  853.       one_stepped = 0;
  854. #endif
  855.       stop_print_frame = 0;
  856.       break;
  857.     }
  858.       else if (!WIFSTOPPED (w))
  859.     {
  860.       stop_print_frame = 0;
  861.       stop_signal = WTERMSIG (w);
  862.       target_terminal_ours ();    /* Must do this before mourn anyway */
  863.       target_kill ();        /* kill mourns as well */
  864. #ifdef PRINT_RANDOM_SIGNAL
  865.       printf ("\nProgram terminated: ");
  866.       PRINT_RANDOM_SIGNAL (stop_signal);
  867. #else
  868.       printf ("\nProgram terminated with signal %d, %s\n",
  869.           stop_signal,
  870.           stop_signal < NSIG
  871.           ? sys_siglist[stop_signal]
  872.           : "(undocumented)");
  873. #endif
  874.       printf ("The inferior process no longer exists.\n");
  875.       fflush (stdout);
  876. #ifdef NO_SINGLE_STEP
  877.       one_stepped = 0;
  878. #endif
  879.       break;
  880.     }
  881.       
  882. #ifdef NO_SINGLE_STEP
  883.       if (one_stepped)
  884.     single_step (0);    /* This actually cleans up the ss */
  885. #endif /* NO_SINGLE_STEP */
  886.       
  887.       stop_pc = read_pc ();
  888.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  889.                         read_pc ()));
  890.       
  891.       stop_frame_address = FRAME_FP (get_current_frame ());
  892.       stop_sp = read_register (SP_REGNUM);
  893.       stop_func_start = 0;
  894.       stop_func_name = 0;
  895.       /* Don't care about return value; stop_func_start and stop_func_name
  896.      will both be 0 if it doesn't work.  */
  897.       (void) find_pc_partial_function (stop_pc, &stop_func_name,
  898.                        &stop_func_start);
  899.       stop_func_start += FUNCTION_START_OFFSET;
  900.       another_trap = 0;
  901.       bpstat_clear (&stop_bpstat);
  902.       stop_step = 0;
  903.       stop_stack_dummy = 0;
  904.       stop_print_frame = 1;
  905.       stop_step_resume_break = 0;
  906.       random_signal = 0;
  907.       stopped_by_random_signal = 0;
  908.       breakpoints_failed = 0;
  909.       
  910.       /* Look at the cause of the stop, and decide what to do.
  911.      The alternatives are:
  912.      1) break; to really stop and return to the debugger,
  913.      2) drop through to start up again
  914.      (set another_trap to 1 to single step once)
  915.      3) set random_signal to 1, and the decision between 1 and 2
  916.      will be made according to the signal handling tables.  */
  917.       
  918.       stop_signal = WSTOPSIG (w);
  919.       
  920.       /* First, distinguish signals caused by the debugger from signals
  921.      that have to do with the program's own actions.
  922.      Note that breakpoint insns may cause SIGTRAP or SIGILL
  923.      or SIGEMT, depending on the operating system version.
  924.      Here we detect when a SIGILL or SIGEMT is really a breakpoint
  925.      and change it to SIGTRAP.  */
  926.       
  927.       if (stop_signal == SIGTRAP
  928.       || (breakpoints_inserted &&
  929.           (stop_signal == SIGILL
  930.            || stop_signal == SIGEMT))
  931.       || stop_soon_quietly)
  932.     {
  933.       if (stop_signal == SIGTRAP && stop_after_trap)
  934.         {
  935.           stop_print_frame = 0;
  936.           break;
  937.         }
  938.       if (stop_soon_quietly)
  939.         break;
  940.  
  941.       /* Don't even think about breakpoints
  942.          if just proceeded over a breakpoint.
  943.  
  944.          However, if we are trying to proceed over a breakpoint
  945.          and end up in sigtramp, then step_resume_break_address
  946.          will be set and we should check whether we've hit the
  947.          step breakpoint.  */
  948.       if (stop_signal == SIGTRAP && trap_expected
  949.           && step_resume_break_address == 0)
  950.         bpstat_clear (&stop_bpstat);
  951.       else
  952.         {
  953.           /* See if there is a breakpoint at the current PC.  */
  954. #if DECR_PC_AFTER_BREAK
  955.           /* Notice the case of stepping through a jump
  956.          that lands just after a breakpoint.
  957.          Don't confuse that with hitting the breakpoint.
  958.          What we check for is that 1) stepping is going on
  959.          and 2) the pc before the last insn does not match
  960.          the address of the breakpoint before the current pc.  */
  961.           if (prev_pc == stop_pc - DECR_PC_AFTER_BREAK
  962.           || !step_range_end
  963.           || step_resume_break_address
  964.           || handling_longjmp /* FIXME */)
  965. #endif /* DECR_PC_AFTER_BREAK not zero */
  966.         {
  967.           /* See if we stopped at the special breakpoint for
  968.              stepping over a subroutine call.  If both are zero,
  969.              this wasn't the reason for the stop.  */
  970.           if (step_resume_break_address
  971.               && stop_pc - DECR_PC_AFTER_BREAK
  972.                  == step_resume_break_address)
  973.             {
  974.               stop_step_resume_break = 1;
  975.               if (DECR_PC_AFTER_BREAK)
  976.             {
  977.               stop_pc -= DECR_PC_AFTER_BREAK;
  978.               write_register (PC_REGNUM, stop_pc);
  979.               pc_changed = 0;
  980.             }
  981.             }
  982.           else
  983.             {
  984.               stop_bpstat =
  985.             bpstat_stop_status (&stop_pc, stop_frame_address);
  986.               /* Following in case break condition called a
  987.              function.  */
  988.               stop_print_frame = 1;
  989.             }
  990.         }
  991.         }
  992.       
  993.       if (stop_signal == SIGTRAP)
  994.         random_signal
  995.           = !(bpstat_explains_signal (stop_bpstat)
  996.           || trap_expected
  997.           || stop_step_resume_break
  998.           || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  999.           || (step_range_end && !step_resume_break_address));
  1000.       else
  1001.         {
  1002.           random_signal
  1003.         = !(bpstat_explains_signal (stop_bpstat)
  1004.             || stop_step_resume_break
  1005.             /* End of a stack dummy.  Some systems (e.g. Sony
  1006.                news) give another signal besides SIGTRAP,
  1007.                so check here as well as above.  */
  1008.             || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
  1009.             );
  1010.           if (!random_signal)
  1011.         stop_signal = SIGTRAP;
  1012.         }
  1013.     }
  1014.       else
  1015.     random_signal = 1;
  1016.       
  1017.       /* For the program's own signals, act according to
  1018.      the signal handling tables.  */
  1019.  
  1020.       if (random_signal)
  1021.     {
  1022.       /* Signal not for debugging purposes.  */
  1023.       int printed = 0;
  1024.       
  1025.       stopped_by_random_signal = 1;
  1026.       
  1027.       if (stop_signal >= NSIG
  1028.           || signal_print[stop_signal])
  1029.         {
  1030.           printed = 1;
  1031.           target_terminal_ours_for_output ();
  1032. #ifdef PRINT_RANDOM_SIGNAL
  1033.           PRINT_RANDOM_SIGNAL (stop_signal);
  1034. #else
  1035.           printf ("\nProgram received signal %d, %s\n",
  1036.               stop_signal,
  1037.               stop_signal < NSIG
  1038.               ? sys_siglist[stop_signal]
  1039.               : "(undocumented)");
  1040. #endif /* PRINT_RANDOM_SIGNAL */
  1041.           fflush (stdout);
  1042.         }
  1043.       if (stop_signal >= NSIG
  1044.           || signal_stop[stop_signal])
  1045.         break;
  1046.       /* If not going to stop, give terminal back
  1047.          if we took it away.  */
  1048.       else if (printed)
  1049.         target_terminal_inferior ();
  1050.  
  1051.       /* Note that virtually all the code below does `if !random_signal'.
  1052.          Perhaps this code should end with a goto or continue.  At least
  1053.          one (now fixed) bug was caused by this -- a !random_signal was
  1054.          missing in one of the tests below.  */
  1055.     }
  1056.  
  1057.       /* Handle cases caused by hitting a breakpoint.  */
  1058.  
  1059.       if (!random_signal)
  1060.     if (bpstat_explains_signal (stop_bpstat))
  1061.       {
  1062.         CORE_ADDR jmp_buf_pc;
  1063.  
  1064.         switch (stop_bpstat->breakpoint_at->type) /* FIXME */
  1065.           {
  1066.         /* If we hit the breakpoint at longjmp, disable it for the
  1067.            duration of this command.  Then, install a temporary
  1068.            breakpoint at the target of the jmp_buf. */
  1069.           case bp_longjmp:
  1070.         disable_longjmp_breakpoint();
  1071.         remove_breakpoints ();
  1072.         breakpoints_inserted = 0;
  1073.         if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
  1074.  
  1075.         /* Need to blow away step-resume breakpoint, as it
  1076.            interferes with us */
  1077.         remove_step_breakpoint ();
  1078.         step_resume_break_address = 0;
  1079.         stop_step_resume_break = 0;
  1080.  
  1081. #if 0                /* FIXME - Need to implement nested temporary breakpoints */
  1082.         if (step_over_calls > 0)
  1083.           set_longjmp_resume_breakpoint(jmp_buf_pc,
  1084.                         get_current_frame());
  1085.         else
  1086. #endif                /* 0 */
  1087.           set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
  1088.         handling_longjmp = 1; /* FIXME */
  1089.         goto keep_going;
  1090.  
  1091.           case bp_longjmp_resume:
  1092.         remove_breakpoints ();
  1093.         breakpoints_inserted = 0;
  1094. #if 0                /* FIXME - Need to implement nested temporary breakpoints */
  1095.         if (step_over_calls
  1096.             && (stop_frame_address
  1097.             INNER_THAN step_frame_address))
  1098.           {
  1099.             another_trap = 1;
  1100.             goto keep_going;
  1101.           }
  1102. #endif                /* 0 */
  1103.         disable_longjmp_breakpoint();
  1104.         handling_longjmp = 0; /* FIXME */
  1105.         break;
  1106.  
  1107.           default:
  1108.         fprintf(stderr, "Unknown breakpoint type %d\n",
  1109.             stop_bpstat->breakpoint_at->type);
  1110.           case bp_watchpoint:
  1111.           case bp_breakpoint:
  1112.           case bp_until:
  1113.           case bp_finish:
  1114.         /* Does a breakpoint want us to stop?  */
  1115.         if (bpstat_stop (stop_bpstat))
  1116.           {
  1117.             stop_print_frame = bpstat_should_print (stop_bpstat);
  1118.             goto stop_stepping;
  1119.           }
  1120.         /* Otherwise, must remove breakpoints and single-step
  1121.            to get us past the one we hit.  */
  1122.         else
  1123.           {
  1124.             remove_breakpoints ();
  1125.             remove_step_breakpoint ();
  1126.             breakpoints_inserted = 0;
  1127.             another_trap = 1;
  1128.           }
  1129.         break;
  1130.           }
  1131.       }
  1132.     else if (stop_step_resume_break)
  1133.       {
  1134.         /* But if we have hit the step-resumption breakpoint,
  1135.            remove it.  It has done its job getting us here.
  1136.            The sp test is to make sure that we don't get hung
  1137.            up in recursive calls in functions without frame
  1138.            pointers.  If the stack pointer isn't outside of
  1139.            where the breakpoint was set (within a routine to be
  1140.            stepped over), we're in the middle of a recursive
  1141.            call. Not true for reg window machines (sparc)
  1142.            because the must change frames to call things and
  1143.            the stack pointer doesn't have to change if it
  1144.            the bp was set in a routine without a frame (pc can
  1145.            be stored in some other window).
  1146.            
  1147.            The removal of the sp test is to allow calls to
  1148.            alloca.  Nasty things were happening.  Oh, well,
  1149.            gdb can only handle one level deep of lack of
  1150.            frame pointer. */
  1151.  
  1152.         /*
  1153.           Disable test for step_frame_address match so that we always stop even if the
  1154.           frames don't match.  Reason: if we hit the step_resume_breakpoint, there is
  1155.           no way to temporarily disable it so that we can step past it.  If we leave
  1156.           the breakpoint in, then we loop forever repeatedly hitting, but never
  1157.           getting past the breakpoint.  This change keeps nexting over recursive
  1158.           function calls from hanging gdb.
  1159.           */
  1160. #if 0
  1161.         if (* step_frame_address == 0
  1162.         || (step_frame_address == stop_frame_address))
  1163. #endif
  1164.           {
  1165.         remove_step_breakpoint ();
  1166.         step_resume_break_address = 0;
  1167.  
  1168.         /* If were waiting for a trap, hitting the step_resume_break
  1169.            doesn't count as getting it.  */
  1170.         if (trap_expected)
  1171.           another_trap = 1;
  1172.           }
  1173.       }
  1174.  
  1175.       /* We come here if we hit a breakpoint but should not
  1176.      stop for it.  Possibly we also were stepping
  1177.      and should stop for that.  So fall through and
  1178.      test for stepping.  But, if not stepping,
  1179.      do not stop.  */
  1180.  
  1181.       /* If this is the breakpoint at the end of a stack dummy,
  1182.      just stop silently.  */
  1183.       if (!random_signal 
  1184.      && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address))
  1185.       {
  1186.         stop_print_frame = 0;
  1187.         stop_stack_dummy = 1;
  1188. #ifdef HP_OS_BUG
  1189.         trap_expected_after_continue = 1;
  1190. #endif
  1191.         break;
  1192.       }
  1193.       
  1194.       if (step_resume_break_address)
  1195.     /* Having a step-resume breakpoint overrides anything
  1196.        else having to do with stepping commands until
  1197.        that breakpoint is reached.  */
  1198.     ;
  1199.       /* If stepping through a line, keep going if still within it.  */
  1200.       else if (!random_signal
  1201.            && step_range_end
  1202.            && stop_pc >= step_range_start
  1203.            && stop_pc < step_range_end
  1204.            /* The step range might include the start of the
  1205.           function, so if we are at the start of the
  1206.           step range and either the stack or frame pointers
  1207.           just changed, we've stepped outside */
  1208.            && !(stop_pc == step_range_start
  1209.             && stop_frame_address
  1210.             && (stop_sp INNER_THAN prev_sp
  1211.             || stop_frame_address != step_frame_address)))
  1212.     {
  1213.       ;
  1214.     }
  1215.       
  1216.       /* We stepped out of the stepping range.  See if that was due
  1217.      to a subroutine call that we should proceed to the end of.  */
  1218.       else if (!random_signal && step_range_end)
  1219.     {
  1220.       if (stop_func_start)
  1221.         {
  1222.           prologue_pc = stop_func_start;
  1223.           SKIP_PROLOGUE (prologue_pc);
  1224.         }
  1225.  
  1226.       /* Did we just take a signal?  */
  1227.       if (IN_SIGTRAMP (stop_pc, stop_func_name)
  1228.           && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1229.         {
  1230.           /* This code is needed at least in the following case:
  1231.          The user types "next" and then a signal arrives (before
  1232.          the "next" is done).  */
  1233.           /* We've just taken a signal; go until we are back to
  1234.          the point where we took it and one more.  */
  1235.           step_resume_break_address = prev_pc;
  1236.           step_resume_break_duplicate =
  1237.         breakpoint_here_p (step_resume_break_address);
  1238.           if (breakpoints_inserted)
  1239.         insert_step_breakpoint ();
  1240.           /* Make sure that the stepping range gets us past
  1241.          that instruction.  */
  1242.           if (step_range_end == 1)
  1243.         step_range_end = (step_range_start = prev_pc) + 1;
  1244.           remove_breakpoints_on_following_step = 1;
  1245.           goto save_pc;
  1246.         }
  1247.  
  1248.       /* ==> See comments at top of file on this algorithm.  <==*/
  1249.       
  1250.       if ((stop_pc == stop_func_start
  1251.            || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name))
  1252.           && (stop_func_start != prev_func_start
  1253.           || prologue_pc != stop_func_start
  1254.           || stop_sp != prev_sp))
  1255.         {
  1256.           /* It's a subroutine call.
  1257.          (0)  If we are not stepping over any calls ("stepi"), we
  1258.               just stop.
  1259.          (1)  If we're doing a "next", we want to continue through
  1260.               the call ("step over the call").
  1261.          (2)  If we are in a function-call trampoline (a stub between
  1262.               the calling routine and the real function), locate
  1263.               the real function and change stop_func_start.
  1264.          (3)  If we're doing a "step", and there are no debug symbols
  1265.               at the target of the call, we want to continue through
  1266.               it ("step over the call").
  1267.          (4)  Otherwise, we want to stop soon, after the function
  1268.               prologue ("step into the call"). */
  1269.  
  1270.           if (step_over_calls == 0)
  1271.         {
  1272.           /* I presume that step_over_calls is only 0 when we're
  1273.              supposed to be stepping at the assembly language level. */
  1274.           stop_step = 1;
  1275.           break;
  1276.         }
  1277.  
  1278.           if (step_over_calls > 0)
  1279.         goto step_over_function;
  1280.  
  1281.           tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
  1282.           if (tmp != 0)
  1283.         stop_func_start = tmp;
  1284.  
  1285.           if (find_pc_function (stop_func_start) != 0)
  1286.             goto step_into_function;
  1287.  
  1288. step_over_function:
  1289.           /* A subroutine call has happened.  */
  1290.           /* Set a special breakpoint after the return */
  1291.           step_resume_break_address =
  1292.         ADDR_BITS_REMOVE
  1293.           (SAVED_PC_AFTER_CALL (get_current_frame ()));
  1294.           step_resume_break_duplicate
  1295.         = breakpoint_here_p (step_resume_break_address);
  1296.           if (breakpoints_inserted)
  1297.         insert_step_breakpoint ();
  1298.           goto save_pc;
  1299.  
  1300. step_into_function:
  1301.           /* Subroutine call with source code we should not step over.
  1302.          Do step to the first line of code in it.  */
  1303.           SKIP_PROLOGUE (stop_func_start);
  1304.           sal = find_pc_line (stop_func_start, 0);
  1305.           /* Use the step_resume_break to step until
  1306.          the end of the prologue, even if that involves jumps
  1307.          (as it seems to on the vax under 4.2).  */
  1308.           /* If the prologue ends in the middle of a source line,
  1309.          continue to the end of that source line.
  1310.          Otherwise, just go to end of prologue.  */
  1311. #ifdef PROLOGUE_FIRSTLINE_OVERLAP
  1312.           /* no, don't either.  It skips any code that's
  1313.          legitimately on the first line.  */
  1314. #else
  1315.           if (sal.end && sal.pc != stop_func_start)
  1316.         stop_func_start = sal.end;
  1317. #endif
  1318.  
  1319.           if (stop_func_start == stop_pc)
  1320.         {
  1321.           /* We are already there: stop now.  */
  1322.           stop_step = 1;
  1323.           break;
  1324.         }    
  1325.           else
  1326.         /* Put the step-breakpoint there and go until there. */
  1327.         {
  1328.           step_resume_break_address = stop_func_start;
  1329.           
  1330.           step_resume_break_duplicate
  1331.             = breakpoint_here_p (step_resume_break_address);
  1332.           if (breakpoints_inserted)
  1333.             insert_step_breakpoint ();
  1334.           /* Do not specify what the fp should be when we stop
  1335.              since on some machines the prologue
  1336.              is where the new fp value is established.  */
  1337.           step_frame_address = 0;
  1338.           /* And make sure stepping stops right away then.  */
  1339.           step_range_end = step_range_start;
  1340.         }
  1341.           goto save_pc;
  1342.         }
  1343.  
  1344.       /* We've wandered out of the step range (but haven't done a
  1345.          subroutine call or return).  */
  1346.  
  1347.       sal = find_pc_line(stop_pc, 0);
  1348.       
  1349.       if (step_range_end == 1 ||    /* stepi or nexti */
  1350.           sal.line == 0 ||        /* ...or no line # info */
  1351.           (stop_pc == sal.pc    /* ...or we're at the start */
  1352.            && current_line != sal.line)) {    /* of a different line */
  1353.         /* Stop because we're done stepping.  */
  1354.         stop_step = 1;
  1355.         break;
  1356.       } else {
  1357.         /* We aren't done stepping, and we have line number info for $pc.
  1358.            Optimize by setting the step_range for the line.  
  1359.            (We might not be in the original line, but if we entered a
  1360.            new line in mid-statement, we continue stepping.  This makes 
  1361.            things like for(;;) statements work better.)  */
  1362.         step_range_start = sal.pc;
  1363.         step_range_end = sal.end;
  1364.         goto save_pc;
  1365.       }
  1366.       /* We never fall through here */
  1367.     }
  1368.  
  1369.       if (trap_expected
  1370.       && IN_SIGTRAMP (stop_pc, stop_func_name)
  1371.       && !IN_SIGTRAMP (prev_pc, prev_func_name))
  1372.     {
  1373.       /* What has happened here is that we have just stepped the inferior
  1374.          with a signal (because it is a signal which shouldn't make
  1375.          us stop), thus stepping into sigtramp.
  1376.  
  1377.          So we need to set a step_resume_break_address breakpoint
  1378.          and continue until we hit it, and then step.  */
  1379.       step_resume_break_address = prev_pc;
  1380.       /* Always 1, I think, but it's probably easier to have
  1381.          the step_resume_break as usual rather than trying to
  1382.          re-use the breakpoint which is already there.  */
  1383.       step_resume_break_duplicate =
  1384.         breakpoint_here_p (step_resume_break_address);
  1385.       if (breakpoints_inserted)
  1386.         insert_step_breakpoint ();
  1387.       remove_breakpoints_on_following_step = 1;
  1388.       another_trap = 1;
  1389.     }
  1390.  
  1391. /* My apologies to the gods of structured programming. */
  1392. /* Come to this label when you need to resume the inferior.  It's really much
  1393.    cleaner at this time to do a goto than to try and figure out what the
  1394.    if-else chain ought to look like!! */
  1395.  
  1396.     keep_going:
  1397.  
  1398. save_pc:
  1399.       /* Save the pc before execution, to compare with pc after stop.  */
  1400.       prev_pc = read_pc ();    /* Might have been DECR_AFTER_BREAK */
  1401.       prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
  1402.                       BREAK is defined, the
  1403.                       original pc would not have
  1404.                       been at the start of a
  1405.                       function. */
  1406.       prev_func_name = stop_func_name;
  1407.       prev_sp = stop_sp;
  1408.  
  1409.       /* If we did not do break;, it means we should keep
  1410.      running the inferior and not return to debugger.  */
  1411.  
  1412.       if (trap_expected && stop_signal != SIGTRAP)
  1413.     {
  1414.       /* We took a signal (which we are supposed to pass through to
  1415.          the inferior, else we'd have done a break above) and we
  1416.          haven't yet gotten our trap.  Simply continue.  */
  1417.       resume ((step_range_end && !step_resume_break_address)
  1418.           || (trap_expected && !step_resume_break_address)
  1419.           || bpstat_should_step (),
  1420.           stop_signal);
  1421.     }
  1422.       else
  1423.     {
  1424.       /* Either the trap was not expected, but we are continuing
  1425.          anyway (the user asked that this signal be passed to the
  1426.          child)
  1427.            -- or --
  1428.          The signal was SIGTRAP, e.g. it was our signal, but we
  1429.          decided we should resume from it.
  1430.  
  1431.          We're going to run this baby now!
  1432.  
  1433.          Insert breakpoints now, unless we are trying
  1434.          to one-proceed past a breakpoint.  */
  1435.       /* If we've just finished a special step resume and we don't
  1436.          want to hit a breakpoint, pull em out.  */
  1437.       if (!step_resume_break_address &&
  1438.           remove_breakpoints_on_following_step)
  1439.         {
  1440.           remove_breakpoints_on_following_step = 0;
  1441.           remove_breakpoints ();
  1442.           breakpoints_inserted = 0;
  1443.         }
  1444.       else if (!breakpoints_inserted &&
  1445.            (step_resume_break_address != 0 || !another_trap))
  1446.         {
  1447.           insert_step_breakpoint ();
  1448.           breakpoints_failed = insert_breakpoints ();
  1449.           if (breakpoints_failed)
  1450.         break;
  1451.           breakpoints_inserted = 1;
  1452.         }
  1453.  
  1454.       trap_expected = another_trap;
  1455.  
  1456.       if (stop_signal == SIGTRAP)
  1457.         stop_signal = 0;
  1458.  
  1459. #ifdef SHIFT_INST_REGS
  1460.       /* I'm not sure when this following segment applies.  I do know, now,
  1461.          that we shouldn't rewrite the regs when we were stopped by a
  1462.          random signal from the inferior process.  */
  1463.  
  1464.           if (!bpstat_explains_signal (stop_bpstat)
  1465.           && (stop_signal != SIGCLD) 
  1466.               && !stopped_by_random_signal)
  1467.             {
  1468.             CORE_ADDR pc_contents = read_register (PC_REGNUM);
  1469.             CORE_ADDR npc_contents = read_register (NPC_REGNUM);
  1470.             if (pc_contents != npc_contents)
  1471.               {
  1472.               write_register (NNPC_REGNUM, npc_contents);
  1473.               write_register (NPC_REGNUM, pc_contents);
  1474.           }
  1475.             }
  1476. #endif /* SHIFT_INST_REGS */
  1477.  
  1478.       resume ((!step_resume_break_address
  1479.            && !handling_longjmp
  1480.            && (step_range_end
  1481.                || trap_expected))
  1482.           || bpstat_should_step (),
  1483.           stop_signal);
  1484.     }
  1485.     }
  1486.  
  1487.  stop_stepping:
  1488.   if (target_has_execution)
  1489.     {
  1490.       /* Assuming the inferior still exists, set these up for next
  1491.      time, just like we did above if we didn't break out of the
  1492.      loop.  */
  1493.       prev_pc = read_pc ();
  1494.       prev_func_start = stop_func_start;
  1495.       prev_func_name = stop_func_name;
  1496.       prev_sp = stop_sp;
  1497.     }
  1498. }
  1499.  
  1500. /* Here to return control to GDB when the inferior stops for real.
  1501.    Print appropriate messages, remove breakpoints, give terminal our modes.
  1502.  
  1503.    STOP_PRINT_FRAME nonzero means print the executing frame
  1504.    (pc, function, args, file, line number and line text).
  1505.    BREAKPOINTS_FAILED nonzero means stop was due to error
  1506.    attempting to insert breakpoints.  */
  1507.  
  1508. void
  1509. normal_stop ()
  1510. {
  1511.   /* Make sure that the current_frame's pc is correct.  This
  1512.      is a correction for setting up the frame info before doing
  1513.      DECR_PC_AFTER_BREAK */
  1514.   if (target_has_execution)
  1515.     (get_current_frame ())->pc = read_pc ();
  1516.   
  1517.   if (breakpoints_failed)
  1518.     {
  1519.       target_terminal_ours_for_output ();
  1520.       print_sys_errmsg ("ptrace", breakpoints_failed);
  1521.       printf ("Stopped; cannot insert breakpoints.\n\
  1522. The same program may be running in another process.\n");
  1523.     }
  1524.  
  1525.   if (target_has_execution)
  1526.     remove_step_breakpoint ();
  1527.  
  1528.   if (target_has_execution && breakpoints_inserted)
  1529.     if (remove_breakpoints ())
  1530.       {
  1531.     target_terminal_ours_for_output ();
  1532.     printf ("Cannot remove breakpoints because program is no longer writable.\n\
  1533. It might be running in another process.\n\
  1534. Further execution is probably impossible.\n");
  1535.       }
  1536.  
  1537.   breakpoints_inserted = 0;
  1538.  
  1539.   /* Delete the breakpoint we stopped at, if it wants to be deleted.
  1540.      Delete any breakpoint that is to be deleted at the next stop.  */
  1541.  
  1542.   breakpoint_auto_delete (stop_bpstat);
  1543.  
  1544.   /* If an auto-display called a function and that got a signal,
  1545.      delete that auto-display to avoid an infinite recursion.  */
  1546.  
  1547.   if (stopped_by_random_signal)
  1548.     disable_current_display ();
  1549.  
  1550.   if (step_multi && stop_step)
  1551.     return;
  1552.  
  1553.   target_terminal_ours ();
  1554.  
  1555.   if (!target_has_stack)
  1556.     return;
  1557.  
  1558.   /* Select innermost stack frame except on return from a stack dummy routine,
  1559.      or if the program has exited.  Print it without a level number if
  1560.      we have changed functions or hit a breakpoint.  Print source line
  1561.      if we have one.  */
  1562.   if (!stop_stack_dummy)
  1563.     {
  1564.       select_frame (get_current_frame (), 0);
  1565.  
  1566.       if (stop_print_frame)
  1567.     {
  1568.       int source_only;
  1569.  
  1570.       source_only = bpstat_print (stop_bpstat);
  1571.       source_only = source_only ||
  1572.             (   stop_step
  1573.          && step_frame_address == stop_frame_address
  1574.          && step_start_function == find_pc_function (stop_pc));
  1575.  
  1576.           print_stack_frame (selected_frame, -1, source_only? -1: 1);
  1577.  
  1578.       /* Display the auto-display expressions.  */
  1579.       do_displays ();
  1580.     }
  1581.     }
  1582.  
  1583.   /* Save the function value return registers, if we care.
  1584.      We might be about to restore their previous contents.  */
  1585.   if (proceed_to_finish)
  1586.     read_register_bytes (0, stop_registers, REGISTER_BYTES);
  1587.  
  1588.   if (stop_stack_dummy)
  1589.     {
  1590.       /* Pop the empty frame that contains the stack dummy.
  1591.          POP_FRAME ends with a setting of the current frame, so we
  1592.      can use that next. */
  1593.       POP_FRAME;
  1594.       select_frame (get_current_frame (), 0);
  1595.     }
  1596. }
  1597.  
  1598. static void
  1599. insert_step_breakpoint ()
  1600. {
  1601.   if (step_resume_break_address && !step_resume_break_duplicate)
  1602.     target_insert_breakpoint (step_resume_break_address,
  1603.                   step_resume_break_shadow);
  1604. }
  1605.  
  1606. static void
  1607. remove_step_breakpoint ()
  1608. {
  1609.   if (step_resume_break_address && !step_resume_break_duplicate)
  1610.     target_remove_breakpoint (step_resume_break_address,
  1611.                   step_resume_break_shadow);
  1612. }
  1613.  
  1614. int signal_stop_state (signo)
  1615.      int signo;
  1616. {
  1617.   return ((signo >= 0 && signo < NSIG) ? signal_stop[signo] : 0);
  1618. }
  1619.  
  1620. int signal_print_state (signo)
  1621.      int signo;
  1622. {
  1623.   return ((signo >= 0 && signo < NSIG) ? signal_print[signo] : 0);
  1624. }
  1625.  
  1626. int signal_pass_state (signo)
  1627.      int signo;
  1628. {
  1629.   return ((signo >= 0 && signo < NSIG) ? signal_program[signo] : 0);
  1630. }
  1631.  
  1632. static void
  1633. sig_print_header ()
  1634. {
  1635.   printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
  1636. }
  1637.  
  1638. static void
  1639. sig_print_info (number)
  1640.      int number;
  1641. {
  1642.   char *abbrev = sig_abbrev(number);
  1643.   if (abbrev == NULL)
  1644.     printf_filtered ("%d\t\t", number);
  1645.   else
  1646.     printf_filtered ("SIG%s (%d)\t", abbrev, number);
  1647.   printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No");
  1648.   printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No");
  1649.   printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No");
  1650.   printf_filtered ("%s\n", sys_siglist[number]);
  1651. }
  1652.  
  1653. /* Specify how various signals in the inferior should be handled.  */
  1654.  
  1655. static void
  1656. handle_command (args, from_tty)
  1657.      char *args;
  1658.      int from_tty;
  1659. {
  1660.   register char *p = args;
  1661.   int signum = 0;
  1662.   register int digits, wordlen;
  1663.   char *nextarg;
  1664.  
  1665.   if (!args)
  1666.     error_no_arg ("signal to handle");
  1667.  
  1668.   while (*p)
  1669.     {
  1670.       /* Find the end of the next word in the args.  */
  1671.       for (wordlen = 0;
  1672.        p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
  1673.        wordlen++);
  1674.       /* Set nextarg to the start of the word after the one we just
  1675.      found, and null-terminate this one.  */
  1676.       if (p[wordlen] == '\0')
  1677.     nextarg = p + wordlen;
  1678.       else
  1679.     {
  1680.       p[wordlen] = '\0';
  1681.       nextarg = p + wordlen + 1;
  1682.     }
  1683.       
  1684.  
  1685.       for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
  1686.  
  1687.       if (signum == 0)
  1688.     {
  1689.       /* It is the first argument--must be the signal to operate on.  */
  1690.       if (digits == wordlen)
  1691.         {
  1692.           /* Numeric.  */
  1693.           signum = atoi (p);
  1694.           if (signum <= 0 || signum >= NSIG)
  1695.         {
  1696.           p[wordlen] = '\0';
  1697.           error ("Invalid signal %s given as argument to \"handle\".", p);
  1698.         }
  1699.         }
  1700.       else
  1701.         {
  1702.           /* Symbolic.  */
  1703.           signum = sig_number (p);
  1704.           if (signum == -1)
  1705.         error ("No such signal \"%s\"", p);
  1706.         }
  1707.  
  1708.       if (signum == SIGTRAP || signum == SIGINT)
  1709.         {
  1710.           if (!query ("SIG%s is used by the debugger.\nAre you sure you want to change it? ", sig_abbrev (signum)))
  1711.         error ("Not confirmed.");
  1712.         }
  1713.     }
  1714.       /* Else, if already got a signal number, look for flag words
  1715.      saying what to do for it.  */
  1716.       else if (!strncmp (p, "stop", wordlen))
  1717.     {
  1718.       signal_stop[signum] = 1;
  1719.       signal_print[signum] = 1;
  1720.     }
  1721.       else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
  1722.     signal_print[signum] = 1;
  1723.       else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
  1724.     signal_program[signum] = 1;
  1725.       else if (!strncmp (p, "ignore", wordlen))
  1726.     signal_program[signum] = 0;
  1727.       else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
  1728.     signal_stop[signum] = 0;
  1729.       else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
  1730.     {
  1731.       signal_print[signum] = 0;
  1732.       signal_stop[signum] = 0;
  1733.     }
  1734.       else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
  1735.     signal_program[signum] = 0;
  1736.       else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
  1737.     signal_program[signum] = 1;
  1738.       /* Not a number and not a recognized flag word => complain.  */
  1739.       else
  1740.     {
  1741.       error ("Unrecognized or ambiguous flag word: \"%s\".", p);
  1742.     }
  1743.  
  1744.       /* Find start of next word.  */
  1745.       p = nextarg;
  1746.       while (*p == ' ' || *p == '\t') p++;
  1747.     }
  1748.  
  1749.   NOTICE_SIGNAL_HANDLING_CHANGE;
  1750.  
  1751.   if (from_tty)
  1752.     {
  1753.       /* Show the results.  */
  1754.       sig_print_header ();
  1755.       sig_print_info (signum);
  1756.     }
  1757. }
  1758.  
  1759. /* Print current contents of the tables set by the handle command.  */
  1760.  
  1761. static void
  1762. signals_info (signum_exp, from_tty)
  1763.      char *signum_exp;
  1764.      int from_tty;
  1765. {
  1766.   register int i;
  1767.   sig_print_header ();
  1768.  
  1769.   if (signum_exp)
  1770.     {
  1771.       /* First see if this is a symbol name.  */
  1772.       i = sig_number (signum_exp);
  1773.       if (i == -1)
  1774.     {
  1775.       /* Nope, maybe it's an address which evaluates to a signal
  1776.          number.  */
  1777.       i = parse_and_eval_address (signum_exp);
  1778.       if (i >= NSIG || i < 0)
  1779.         error ("Signal number out of bounds.");
  1780.     }
  1781.       sig_print_info (i);
  1782.       return;
  1783.     }
  1784.  
  1785.   printf_filtered ("\n");
  1786.   for (i = 0; i < NSIG; i++)
  1787.     {
  1788.       QUIT;
  1789.  
  1790.       sig_print_info (i);
  1791.     }
  1792.  
  1793.   printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
  1794. }
  1795.  
  1796. /* Save all of the information associated with the inferior<==>gdb
  1797.    connection.  INF_STATUS is a pointer to a "struct inferior_status"
  1798.    (defined in inferior.h).  */
  1799.  
  1800. void
  1801. save_inferior_status (inf_status, restore_stack_info)
  1802.      struct inferior_status *inf_status;
  1803.      int restore_stack_info;
  1804. {
  1805.   inf_status->pc_changed = pc_changed;
  1806.   inf_status->stop_signal = stop_signal;
  1807.   inf_status->stop_pc = stop_pc;
  1808.   inf_status->stop_frame_address = stop_frame_address;
  1809.   inf_status->stop_step = stop_step;
  1810.   inf_status->stop_stack_dummy = stop_stack_dummy;
  1811.   inf_status->stopped_by_random_signal = stopped_by_random_signal;
  1812.   inf_status->trap_expected = trap_expected;
  1813.   inf_status->step_range_start = step_range_start;
  1814.   inf_status->step_range_end = step_range_end;
  1815.   inf_status->step_frame_address = step_frame_address;
  1816.   inf_status->step_over_calls = step_over_calls;
  1817.   inf_status->step_resume_break_address = step_resume_break_address;
  1818.   inf_status->stop_after_trap = stop_after_trap;
  1819.   inf_status->stop_soon_quietly = stop_soon_quietly;
  1820.   /* Save original bpstat chain here; replace it with copy of chain. 
  1821.      If caller's caller is walking the chain, they'll be happier if we
  1822.      hand them back the original chain when restore_i_s is called.  */
  1823.   inf_status->stop_bpstat = stop_bpstat;
  1824.   stop_bpstat = bpstat_copy (stop_bpstat);
  1825.   inf_status->breakpoint_proceeded = breakpoint_proceeded;
  1826.   inf_status->restore_stack_info = restore_stack_info;
  1827.   inf_status->proceed_to_finish = proceed_to_finish;
  1828.   
  1829.   bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
  1830.   
  1831.   record_selected_frame (&(inf_status->selected_frame_address),
  1832.              &(inf_status->selected_level));
  1833.   return;
  1834. }
  1835.  
  1836. void
  1837. restore_inferior_status (inf_status)
  1838.      struct inferior_status *inf_status;
  1839. {
  1840.   FRAME fid;
  1841.   int level = inf_status->selected_level;
  1842.  
  1843.   pc_changed = inf_status->pc_changed;
  1844.   stop_signal = inf_status->stop_signal;
  1845.   stop_pc = inf_status->stop_pc;
  1846.   stop_frame_address = inf_status->stop_frame_address;
  1847.   stop_step = inf_status->stop_step;
  1848.   stop_stack_dummy = inf_status->stop_stack_dummy;
  1849.   stopped_by_random_signal = inf_status->stopped_by_random_signal;
  1850.   trap_expected = inf_status->trap_expected;
  1851.   step_range_start = inf_status->step_range_start;
  1852.   step_range_end = inf_status->step_range_end;
  1853.   step_frame_address = inf_status->step_frame_address;
  1854.   step_over_calls = inf_status->step_over_calls;
  1855.   step_resume_break_address = inf_status->step_resume_break_address;
  1856.   stop_after_trap = inf_status->stop_after_trap;
  1857.   stop_soon_quietly = inf_status->stop_soon_quietly;
  1858.   bpstat_clear (&stop_bpstat);
  1859.   stop_bpstat = inf_status->stop_bpstat;
  1860.   breakpoint_proceeded = inf_status->breakpoint_proceeded;
  1861.   proceed_to_finish = inf_status->proceed_to_finish;
  1862.  
  1863.   bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
  1864.  
  1865.   /* The inferior can be gone if the user types "print exit(0)"
  1866.      (and perhaps other times).  */
  1867.   if (target_has_stack && inf_status->restore_stack_info)
  1868.     {
  1869.       fid = find_relative_frame (get_current_frame (),
  1870.                  &level);
  1871.  
  1872.       /* If inf_status->selected_frame_address is NULL, there was no
  1873.      previously selected frame.  */
  1874.       if (fid == 0 ||
  1875.       FRAME_FP (fid) != inf_status->selected_frame_address ||
  1876.       level != 0)
  1877.     {
  1878. #if 1
  1879.       /* I'm not sure this error message is a good idea.  I have
  1880.          only seen it occur after "Can't continue previously
  1881.          requested operation" (we get called from do_cleanups), in
  1882.          which case it just adds insult to injury (one confusing
  1883.          error message after another.  Besides which, does the
  1884.          user really care if we can't restore the previously
  1885.          selected frame?  */
  1886.       fprintf (stderr, "Unable to restore previously selected frame.\n");
  1887. #endif
  1888.       select_frame (get_current_frame (), 0);
  1889.       return;
  1890.     }
  1891.       
  1892.       select_frame (fid, inf_status->selected_level);
  1893.     }
  1894. }
  1895.  
  1896.  
  1897. void
  1898. _initialize_infrun ()
  1899. {
  1900.   register int i;
  1901.  
  1902.   add_info ("signals", signals_info,
  1903.         "What debugger does when program gets various signals.\n\
  1904. Specify a signal number as argument to print info on that signal only.");
  1905.  
  1906.   add_com ("handle", class_run, handle_command,
  1907.        "Specify how to handle a signal.\n\
  1908. Args are signal number followed by flags.\n\
  1909. Flags allowed are \"stop\", \"print\", \"pass\",\n\
  1910.  \"nostop\", \"noprint\" or \"nopass\".\n\
  1911. Print means print a message if this signal happens.\n\
  1912. Stop means reenter debugger if this signal happens (implies print).\n\
  1913. Pass means let program see this signal; otherwise program doesn't know.\n\
  1914. Pass and Stop may be combined.");
  1915.  
  1916.   for (i = 0; i < NSIG; i++)
  1917.     {
  1918.       signal_stop[i] = 1;
  1919.       signal_print[i] = 1;
  1920.       signal_program[i] = 1;
  1921.     }
  1922.  
  1923.   /* Signals caused by debugger's own actions
  1924.      should not be given to the program afterwards.  */
  1925.   signal_program[SIGTRAP] = 0;
  1926.   signal_program[SIGINT] = 0;
  1927.  
  1928.   /* Signals that are not errors should not normally enter the debugger.  */
  1929. #ifdef SIGALRM
  1930.   signal_stop[SIGALRM] = 0;
  1931.   signal_print[SIGALRM] = 0;
  1932. #endif /* SIGALRM */
  1933. #ifdef SIGVTALRM
  1934.   signal_stop[SIGVTALRM] = 0;
  1935.   signal_print[SIGVTALRM] = 0;
  1936. #endif /* SIGVTALRM */
  1937. #ifdef SIGPROF
  1938.   signal_stop[SIGPROF] = 0;
  1939.   signal_print[SIGPROF] = 0;
  1940. #endif /* SIGPROF */
  1941. #ifdef SIGCHLD
  1942.   signal_stop[SIGCHLD] = 0;
  1943.   signal_print[SIGCHLD] = 0;
  1944. #endif /* SIGCHLD */
  1945. #ifdef SIGCLD
  1946.   signal_stop[SIGCLD] = 0;
  1947.   signal_print[SIGCLD] = 0;
  1948. #endif /* SIGCLD */
  1949. #ifdef SIGIO
  1950.   signal_stop[SIGIO] = 0;
  1951.   signal_print[SIGIO] = 0;
  1952. #endif /* SIGIO */
  1953. #ifdef SIGURG
  1954.   signal_stop[SIGURG] = 0;
  1955.   signal_print[SIGURG] = 0;
  1956. #endif /* SIGURG */
  1957. }
  1958.